<?php if ($this->mode == INSERT_MODE): ?>
    <?php $action = $this->url(); ?>
    <?php $title = 'New Buoy' ?>
<?php else: ?>
    <?php $action = $this->url(array('action' => 'editbuoy')); ?>
    <?php $title = 'Edit Buoy' ?>
<?php endif; ?>

<h1>
    <?php echo $title ?>
</h1>

<form method='POST' action='<?php echo $action ?>' id='frm_newbuoy'>
    <div class='wrap-content'>
        <label>
            Buoy Name
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <input type='text' name='name' value='<?php echo isset($this->buoy) ? $this->buoy->name: '' ?>' id='name'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'name')) ?>
            </div>
        </div>
    </div>                           
    <div class='wrap-content'>
        <label>
            Port
        </label>   
        <div class='content'>    
            <div class='wrap-input'>
                <select id='port' name='port'>
                    <?php foreach ($this->ports as $port): ?>
                        <option value='<?php echo $port->id?>' <?php echo !empty($this->buoy) && ($this->buoy->port == $port->id) ? "selected" : "" ?>>
                            <?php echo $port->name ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'port')) ?>
            </div>
            <input type='submit' value='Add New' class='submit-button' onkeyup='placeMarker()'/>
            <a href='<?php echo $this->url(array('action' => 'buoys', 'module' => 'admin', 'controller' => 'index')) ?>'>
                <input type='button' value='Cancel' class='submit-button'/>
            </a>
        </div>
    </div>
</form>
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js'></script>
<script src='<?php echo $this->baseUrl()?>/public/js/newbuoy.js'></script>